from abc import ABC, abstractmethod
import pandas as pd
from datetime import datetime
from typing import List, Union, Tuple, Dict, Any, Optional

class IDataService(ABC):
    """面向用户和回测类的接口"""
    
    @abstractmethod
    def show_exist_symbols(self, data_type: str) -> pd.DataFrame:
        """显示已存储的标的"""
        pass

    @abstractmethod
    def history(self, symbols: list, start_time: Union[datetime, str], 
               end_time: Union[datetime, str], frequency: str,
               fields: list = None, filter_st: bool = False) -> pd.DataFrame:
        """获取标的的历史交易数据"""
        pass
    
    @abstractmethod
    def get_group_positions(self, symbols: list) -> list:
        """获取标的集合的持仓信息"""
        pass

     # 数据更新
    @abstractmethod
    def update_today_data(self, min: bool = True, tick: bool = False):
        """更新今日交易数据"""
        pass
    
    # 回测结果管理
    @abstractmethod
    def save_backtest_result(self, summary: dict, daily_data: pd.DataFrame):
        """保存回测结果"""
        pass
    
    @abstractmethod
    def get_backtest_list(self) -> list:
        """获取回测列表"""
        pass
    
    @abstractmethod
    def get_backtest_detail(self, backtest_name: str) -> Tuple[dict, pd.DataFrame]:
        """获取回测详情"""
        pass
    
    @abstractmethod
    def delete_backtest(self, backtest_name: str):
        """删除回测结果"""
        pass

class IDatabaseManager(ABC):
    """数据库管理操作"""
    
    # 标的操作
    @abstractmethod
    def change_symbol_name(self, symbol: str, new_name: str):
        """修改标的名称"""
        pass
    
    @abstractmethod
    def insert_new_symbol(self, data: pd.DataFrame, data_type: str):
        """插入新标的数据"""
        pass
    
    @abstractmethod
    def delete_symbol(self, symbol: str, table_type: str, 
                     start_time: Union[datetime, str] = None, 
                     end_time: Union[datetime, str] = None, 
                     force: bool = False):
        """删除标的数据"""
        pass
    
    @abstractmethod
    def insert_new_group(self, symbol: str, position: list = None):
        """插入新的标的集合"""
        pass
    
    @abstractmethod
    def delete_group(self, symbol: str):
        """删除标的集合"""
        pass
    
    @abstractmethod
    def insert_new_name(self, symbol: str, name_str: str):
        """插入标的名称"""
        pass
    
   